'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 来袭技能消耗
 * @author sundbcn@gmail.com (sun debing)
 */

var async = require('async');
var Code = require('../../../consts/code');
var rebelConf = require('../../../config/rebelConf');
var PlayerManager = require('../../../libs/playerManager');
var roleService = require('../../../services/roleService');

module.exports = function (app) {
    return new Handler(app);
};

var Handler = function (app) {
    this.app = app;
};

Handler.prototype.use = function (msg, session, next) {
    var role_id = session.uid;
    var skill_type = msg.skill_type;
    if (!skill_type) {
        return next(null, {
            code: Code.PARAM_ERROR
        });
    }

    // 关闭功能
    return next(null, {
        code: Code.FAIL
    });

    // var sub_gold;
    // var player_manager = new PlayerManager(role_id);

    // async.waterfall(
    //     [
    //         function (cb) {
    //             player_manager.refreshData(cb);
    //         },
    //         function (cb) {
    //             player_manager.getModel(
    //                 ['rebel', 'role', 'bag', 'build', 'task', 'daily_task', 'achieve', 'sevenDayActivity', 'accrued'],
    //                 cb);
    //         },
    //         function (cb) {
    //             var role_model = player_manager.role;
    //             var rebel_model = player_manager.rebel;

    //             var rebel_conf = rebelConf.getRebelSkill(skill_type);

    //             // 扣除金币
    //             sub_gold = rebel_conf.cost_gold;
    //             if (!roleService.subGold(player_manager, sub_gold)) {
    //                 return next(null, {
    //                     code: Code.USER_GOLD_NOT_ENOUGH
    //                 });
    //             }

    //             rebel_model.addRebelSkill(skill_type);
    //             player_manager.save(cb);
    //         }
    //     ],
    //     function (err) {
    //         if (!!err) {
    //             console.error(err);
    //             return next(null, {
    //                 code: Code.FAIL
    //             });
    //         }
    //         return next(null, {
    //             code: Code.OK,
    //             result: {
    //                 sub_gold: sub_gold,
    //                 skill_type: skill_type
    //             }
    //         });
    //     }
    // );
};
